﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BKH.BLL;


namespace BKH.MyUserControl.UCHienThi
{
    public partial class ucLichSuKham : UserControl
    {
        int idBN;
        public ucLichSuKham(int idbn)
        {
            InitializeComponent();
            this.idBN = idbn;
            showInfoBN();
            showLichSuKham();
        }

        void showInfoBN()
        {
            BenhNhanBUO bn = new BenhNhanBUO();
            tbl_BenhNhan obj=bn.GetSingle(idBN);
            lblBenhNhan.Text = obj.FirstName + " " + obj.LastName;
            lblCMND.Text = obj.CMND;
            lblBHYT.Text = obj.BHYT;
        }

        void showLichSuKham()
        {
            HospitalDBDataContext context = new HospitalDBDataContext();
            BenhNhanBUO bn = new BenhNhanBUO();
            String cmnd = bn.GetCMND(idBN);
            var lskham = context.tbl_BenhNhans.Join(context.tbl_BenhNhan_LanKhams,
                a => a.BenhNhanID,
                b => b.BenhNhanID,
                (a, b) => new
                {                   
                    Ho=a.FirstName,
                    Ten=a.LastName,
                    CMND=a.CMND,
                    NgayKham=b.NgayKham,
                    PhongKham=b.Room,
                    ChanDoan=b.ChuanDoan
                }
            ).Where(c=>c.CMND.Equals(cmnd)).ToList();
            dataGridView1.AutoGenerateColumns = false;
            dataGridView1.DataSource = lskham;

        }
    }
}
